﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class FomulaRestore
    {
        public FomulaRestore()
        {
            int testCount = Int32.Parse(TestConsole.ReadLine());

            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                string[] input = TestConsole.ReadLine().Trim().Split(' ');
                string firstA = input[0];
                string firstB = input[2];
                string firstC = input[4];
                int maxCount = Math.Max(Math.Max(input[0].Length, input[2].Length), input[4].Length);
                Rapper a = new Rapper(new int[maxCount]);
                Rapper b = new Rapper(new int[maxCount]);
                Rapper c = new Rapper(new int[maxCount]);
                for (int i = 0; i < maxCount; i++)
                {
                    int intent = maxCount - firstA.Length;
                    a[i] = i < intent ? 0 :
                        firstA[i - intent] == '?' ? -1 : Int32.Parse(firstA[i - intent].ToString());
                    intent = maxCount - firstB.Length;
                    b[i] = i < intent ? 0 :
                        firstB[i - intent] == '?' ? -1 : Int32.Parse(firstB[i - intent].ToString());
                    intent = maxCount - firstC.Length;
                    c[i] = i < intent ? 0 :
                        firstC[i - intent] == '?' ? -1 : Int32.Parse(firstC[i - intent].ToString());
                }
                int op = (input[1][0] == '+') ? 1 : -1;

                int to = 0;
                for (int i = 0; i < maxCount; i++)
                {
                    to = Solve(a, b, c, op, i);
                    if (to != 0)
                    {
                        Add(a, b, c, firstA, firstB, firstC, i, to);
                    }
                }
                

                Console.WriteLine("Case #" + testCase + ": " + a + (op > 0 ? " + " : " - ")  + b + " = " + c );
            }
        }
        /// <summary>
        /// index 위치의 물음표의 최적값을 구해줌
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="index"></param>
        private int Solve(Rapper a, Rapper b, Rapper c, int op, int index)
        {
            int to = 0;
            int x = a[index];
            int y = b[index];
            int z = c[index];

            if (x < 0 && y >= 0 && z >= 0) // x = ?
            {
                x = z - (y * op);
            }
            else if (x >= 0 && y < 0 && z >= 0) // y = ?
            {
                y = (z - x) * op;
            }
            else if (x >= 0 && y >= 0 && z < 0) // z = ?
            {
                z = x + (y * op);
            }
            else if (x < 0 && y < 0 && z >= 0) // x,y = ?
            {
                x = 0;
                y = z - (x * op);
            }
            else if (x < 0 && y >= 0 && z < 0) // x,z = ?
            {
                x = 0;
                z = x + (y * op);
            }
            else if (x >= 0 && y < 0 && z < 0) // y,z = ?
            {
                y = 0;
                z = x + (y * op);
            }
            else if (x < 0 && y < 0 && z < 0) // x, y,z = ?
            {
                x = 0;
                y = 0;
                z = x + (y * op);
            }
             
            if (x < 0)
            {
                x = 10 + x;
                to = 1;
            }
            else if (x > 9)
            {
                x -= 10;
                to = -1;
            }
            if (y < 0)
            {
                y = 10 + y;
                to = -1;
            }
            else if (y > 9)
            {
                throw new Exception("Error!!!");
            }
            if (z < 0)
            {
                z = 10 + z;
                to = 1;
            }
            else if (z > 9)
            {
                z -= 10;
                to = -1;
            }
            a[index] = x;
            b[index] = y;
            c[index] = z;

            return to;

        }
        /// <summary>
        /// index 위치에 추가 수정이 필요함
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="index"></param>
        private void Add(Rapper a, Rapper b, Rapper c, string firstA, string firstB, string firstC, int index, int to)
        {
            int x = a[index];
            int y = b[index];
            int z = c[index];
            bool qA = firstA[index] == '?';
            bool qB = firstB[index] == '?';
            bool qC = firstC[index] == '?';
            if (to < 0)
            {
                if (qA && x > 0) { x--; }
                else if (qB && y > 0) { y--; }
                else if (qC && z > 0) { z--; }
            }
            else
            {
                if (qC && z > 0) { z--; }
                else if (qB && y > 0) { y--; }
                else if (qA && x > 0) { x--; }
            }
        }
        class Rapper
        {
            public int[] Array { get; set; }
            public Rapper(int[] number)
            {
                Array = number;
            }
            public int this[int index]
            {   // Indexer declaration
                get
                {
                    return Array[index];
                }
                set
                {
                    Array[index] = value;
                }
            }
            public override string ToString()
            {
                StringBuilder str = new StringBuilder();
                for (int i = 0; i < Array.Length; i++)
                {
                    str.Append(Array[i] + " ");
                }
                return str.Remove(str.Length - 1, 1).ToString();
            }
        }
    }
}
